#include "myitem.h"
#include <QDebug>
myitem::myitem()
{
    this->setPixmap(QPixmap(":/pic/2"));//默认背景图片
    mouse = false;//没有老鼠
    start = false;//没开始
    this->setCursor(QCursor(QPixmap(":/pic/up1.png")));//鼠标为锤子抬起形态
}

void myitem::setpic(QString path) //用于设置该图元的图片
{
    this->setPixmap(QPixmap(path));
}

void myitem::setmouse(bool m) //设置该图元上是否有老鼠
{
    this->mouse = m;
}
bool myitem::ismouse()//返回该图元上是否有老鼠
{
    return this->mouse;
}

 void myitem::mousePressEvent(QGraphicsSceneMouseEvent *event)//鼠标点击事件重写，继承自父类QGraphicItem
 {
     this->setCursor(QCursor(QPixmap(":/pic/down.png")));//鼠标点击锤子落下
     if(this->start)//判断是否是开始状态
     {
         if(ismouse())//判断是否有老鼠
         {
             this->setPixmap(QPixmap(":/pic/3"));//设置该图元为击中效果
             score* s = score::getscore();//获取单例对象
             s->addscore();//通知加分
         }
     }
 }

 void myitem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)//鼠标释放事件，锤子抬起
 {
     this->setCursor(QCursor(QPixmap(":/pic/up1.png")));
 }
 void myitem::setstart(bool m)//设置是否为开始状态
 {
     this->start = m;
 }
 bool myitem::isstart()
 {
     return this->start;
 }
